#ifndef __GPIO_H__
#define __GPIO_H__
#include "sys.h"
#define	LED_PIN		GPIO_Pin_13
#define I2C2_SCL	GPIO_Pin_10
#define I2C2_SDA	GPIO_Pin_11
#define Light		GPIO_Pin_4
#define Smoke		GPIO_Pin_9
#define Rain		GPIO_Pin_12
#define tem_hum		GPIO_Pin_13
#define buzzer		GPIO_Pin_14
#define hot			GPIO_Pin_15
#define voice		GPIO_Pin_0
#define ADC1_IN4	GPIO_Pin_4
#define ADC1_IN5	GPIO_Pin_5
#define ADC1_IN6	GPIO_Pin_6
#define ADC1_IN7	GPIO_Pin_7

#define KEY1		GPIO_Pin_8
#define KEY2		GPIO_Pin_1
#define KEY3		GPIO_Pin_12
#define KEY4		GPIO_Pin_15
#define KEY1_read 	GPIO_ReadInputDataBit(GPIOA,KEY1)
#define KEY2_read 	GPIO_ReadInputDataBit(GPIOA,KEY2)
#define KEY3_read 	GPIO_ReadInputDataBit(GPIOA,KEY3)
#define KEY4_read 	GPIO_ReadInputDataBit(GPIOA,KEY4)
#define Step_A		GPIO_Pin_5
#define Step_B		GPIO_Pin_6
#define Step_C		GPIO_Pin_7
#define Step_D		GPIO_Pin_8
#define DHT11_IO_IN()  {GPIOB->CRH&=0XFF0FFFFF;GPIOB->CRH|=8<<20;}
#define DHT11_IO_OUT() {GPIOB->CRH&=0XFF0FFFFF;GPIOB->CRH|=3<<20;}
#define	DHT11_DQ_OUT PBout(13)
#define	DHT11_DQ_IN  PBin(13)   
#define IIC_SCL    PBout(10) 
#define IIC_SDA    PBout(11) 	 
#define READ_SDA   PBin(11) 
#define OLED_ADDRESS	0x78 
#define OLED_data_address 0x40
#define OLED_cmd_address 0x00
#define CLIP_ROT(V,MIN,MAX) ( ( V>MAX?MIN:(V<MIN?MAX:V) ) )
void GpioInit(void);
void step_on(void);
void step_off(void);
void buzzer_on(void);
void buzzer_off(void);
uint8_t get_light_level(void);
uint8_t get_smoke_level(void);
uint8_t get_rain_level(void);
uint8_t get_hot_level(void);
uint8_t get_voice_level(void);
uint8_t key_scan(void);
//uint8_t DHT11_ReadByte(void);
//void DHT11_Read(uint8_t *pTemp, uint8_t *pHum);
//void Dht11_OutputMode(void);
//void Dht11_InputMode(void);
u8 DHT11_Init(void);
u8 DHT11_Read_Data(u8 *temp,u8 *humi);
u8 DHT11_Read_Byte(void);
u8 DHT11_Read_Bit(void);
u8 DHT11_Check(void);
void DHT11_Rst(void);
void SDA_OUT(void);
void SDA_IN(void);
void IIC_Start(void);
void IIC_Stop(void);
u8 IIC_Wait_Ack(void);
void IIC_Ack(void);
void IIC_NAck(void);
void IIC_Send_Byte(u8 txd);
u8 IIC_Read_Byte(unsigned char ack);
void WriteCmd(unsigned char I2C_Command);
void WriteDat(unsigned char I2C_Data);
void OLED_Init(void);
void OLED_Fill(unsigned char fill_Data);
void OLED_CLS(void);
void OLED_SetPos(unsigned char x, unsigned char y) ;
void OLED_ShowStr(unsigned char x, unsigned char y, uint8_t ch[]);
#endif
